import 'package:cat_eye/bean/home_body_bean.dart';
import 'package:cat_eye/bean/sq_lite_bean.dart';
import 'package:cat_eye/config/string_config.dart';
import 'package:cat_eye/root_page/home_page/video_details_widget.dart';
import 'package:cat_eye/sqflite/sqLite_manager.dart';
import 'package:cat_eye/util/date_util.dart';
import 'package:cat_eye/util/util.dart';
import 'package:flutter/material.dart';

/*
* @Package: root_page.find_page
* @ClassName: find_follow_list_widget
* @Author: szj
* @CreateDate: 8/2/21 2:09 PM
* TODO 发现-关注LiView中的横向ListView页面
*/
class FindFollowListWidget extends StatelessWidget {
  final ItemList itemData;

  const FindFollowListWidget(this.itemData, {Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: itemData.data.itemList.length,
        // 滑动方向：水平
        scrollDirection: Axis.horizontal,
        itemBuilder: (BuildContext context, int index) {
          var item = itemData.data.itemList[index];
          return Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              InkWell(
                onTap: () {
                  //跳转到视频详情页面
                  Navigator.push(context,
                      router(widget: VideoDetailsWidget(data: item.data)));
                },
                child: Container(
                  height: 200,
                  child: Stack(
                    children: [
                      Padding(
                          padding:
                              EdgeInsets.only(left: 10, top:5, bottom: 10),
                          child: cacheImage(item.data.cover.feed,
                              borderRadius: BorderRadius.circular(5))),
                      Positioned(
                          right: 10,
                          top: 10,
                          child: Container(
                            padding: EdgeInsets.only(
                                left: 5, right: 5, top: 3, bottom: 3),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(5)),
                            child: InkWell(
                              onTap: () {
                                SqLiteBean bean = SqLiteBean(
                                    "",
                                    item.data.cover.feed,
                                    itemData.data.header.icon,
                                    item.data.title,
                                    formatDateMsByYMDHM(
                                      item.data.author.latestReleaseTime,
                                    ),
                                    "",
                                    item.data.playUrl,
                                    '${item.data.cover.blurred}');

                                SQLiteManager.getInstance()
                                    .insert(bean, context);
                              },
                              child: Text(
                                StringConfig.FOLLOW,
                                style: TextStyle(
                                  color: Colors.black26,
                                  // fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                          ))
                    ],
                  ),
                ),
              ),
              Padding(
                  padding: EdgeInsets.only(left: 10),
                  child: Text(
                    item.data.title,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(fontWeight: FontWeight.bold),
                    maxLines: 1,
                  )),
              Padding(
                  padding: EdgeInsets.only(left: 10),
                  child: Text(
                    formatDateMsByYMDHM(item.data.author.latestReleaseTime),
                    overflow: TextOverflow.ellipsis,
                    maxLines: 1,
                  ))
            ],
          );
        });
  }
}
